package com.itheima.server.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.itheima.server.service.TanhuaService;
import com.tanhua.model.dto.RecommendQueryDto;
import com.tanhua.model.vo.NearUserVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.TodayBest;
import org.bson.json.JsonParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tanhua")
public class TanhuaController {

    @Autowired
    private TanhuaService tanhuaService;



    /**
     * 接口名称：今日佳人
     * 接口路径： GET/tanhua/todayBest
     */
    @GetMapping("/todayBest")
    public ResponseEntity todayBest() {
        TodayBest vo = tanhuaService.todayBest();
        return ResponseEntity.ok(vo);
    }

    /**
     * 接口名称：推荐朋友
     * 接口路径：GET/tanhua/recommendation
     */
    @GetMapping("/recommendation")
    public ResponseEntity recommendation(RecommendQueryDto recommendQueryDto){
        PageResult pageResult = tanhuaService.recommendation(recommendQueryDto);
        return ResponseEntity.ok(pageResult);
    }

    /**
     *接口名称：佳人信息
     *接口路径：GET/tanhua/:id/personalInfo
     */
    @GetMapping("/{id}/personalInfo")
    public ResponseEntity personalInfo(@PathVariable("id") Long recommendUserId){
        TodayBest todayBest = tanhuaService.personalInfo(recommendUserId);
        return ResponseEntity.ok(todayBest);
    }

    /**
     * 接口名称：查询陌生人问题
     * 接口路径：GET/tanhua/strangerQuestions
     */
    @GetMapping("/strangerQuestions")
    public ResponseEntity strangerQuestions(Long userId){
        String content = tanhuaService.strangerQuestions(userId);
        return ResponseEntity.ok(content);
    }

    /**
     * 接口名称：回复陌生人问题
     * 接口路径：POST/tanhua/strangerQuestion
     */
    @PostMapping("/strangerQuestions")
    public ResponseEntity replyQuestion(@RequestBody Map<String,String> paramMap) throws JsonParseException, JsonProcessingException {
        Long userId = Long.valueOf(paramMap.get("userId"));
        String reply = paramMap.get("reply");
        tanhuaService.replyQuestions(userId,reply);
        return ResponseEntity.ok(null);
    }

    /**
     * 接口名称：探花-卡片
     * 接口路径：GET/tanhua/cards
     */
    @GetMapping("/cards")
    public ResponseEntity cards(){
        List<TodayBest> todayBestList = tanhuaService.queryCardsList();
        return ResponseEntity.ok(todayBestList);
    }

    /**
     * 接口名称：探花-喜欢
     * 接口路径：GET/tanhua/id/love
     */
    @GetMapping("/{id}/love")
    public ResponseEntity likeUser(@PathVariable("id") Long likeUserId){
        this.tanhuaService.likeUser(likeUserId);
        return ResponseEntity.ok(null);
    }
    /**
     * 不喜欢
     */
    @GetMapping("{id}/unlove")
    public ResponseEntity<Void> notLikeUser(@PathVariable("id") Long likeUserId){
        this.tanhuaService.notLikeUser(likeUserId);
        return ResponseEntity.ok(null);
    }

    /**
     * 接口名称：搜附近
     * 接口路径：GET/tanhua/search
     */
    @GetMapping("/search")
    public ResponseEntity queryNearUser(String gender,Integer distance){
        List<NearUserVo> voList = tanhuaService.queryNearUser(gender,distance);
        return ResponseEntity.ok(voList);
    }

}